package Server;

import databaseHandling.DatabaseHandler;
import interfaces.GourmetGrossistInterface;
import java.io.IOException;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import model.GourmetGrossist;

/**
 *
 * @author Maja
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {        
            DatabaseHandler.getInstance().openConn(null);
        } catch (SQLException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParseException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
            try {
            Registry reg = java.rmi.registry.LocateRegistry.createRegistry(1099);

            System.out.println("Getting GourmetGrossist...");
            GourmetGrossistInterface gourmetGrossist = GourmetGrossist.getInstance();

            System.out.println("Binding chat to registry...");
            Context nameContext = new InitialContext();
            nameContext.bind("rmi:Gourmet", gourmetGrossist);
            System.out.println("Waiting for client....");
        } catch (NamingException ex) {
                System.out.println(ex.getMessage());
        } catch (RemoteException ex) {
                System.out.println(ex.getMessage());
        }
    }
    
}
